#!/usr/bin/env python
# -*- coding: utf8 -*-
# title       :
# description :
# author      :'ShenMeng'



from .manager_widget import BatchManagerUi
from PySide import QtGui
import functools


def singleton(cls, *args, **kwargs):
    @functools.wraps(cls)
    def _singleton(*args, **kwargs):
        import socket
        try:
            # 全局属性，否则变量会在方法退出后被销毁
            global s
            s = socket.socket()
            host = socket.gethostname()
            s.bind((host, 28114))
        except:
            print('already has an instance')
            return None
        return cls(*args, **kwargs)
    return _singleton

#@singleton
class MainWindow():
    def __init__(self, config=None, parent=None):
        self._app = QtGui.QApplication([])
        #QtGui.QApplication.setQuitOnLastWindowClosed(False)
        self.window = BatchManagerUi(config=config, parent=parent)
        self._app.installEventFilter(self.window)

    def show(self):
        self.window.show()
        self._app.exec_()
